<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>系统角色列表</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <include file="Index/common_css"/>
    <link href="__PUBLIC__/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
</head>

<body>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <form action="__MODULE__/System/" method="post" class="form form-horizontal" id="form-admin-role-add" onsubmit="return false">
            <div class="form-group">
                <label class="col-sm-3 control-label">角色名称：</label>
                <div class="col-sm-8">
                    <input id="roleName" name="role_name"  value="{$role_one['role_name']}" class="form-control" type="text"  datatype="*4-16" nullmsg="用户账户不能为空">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">描述：</label>
                <div class="col-sm-8">
                    <input id="roleResp" name="role_desp"  value="{$role_one['role_desp']}" class="form-control" type="text"  datatype="*4-16" nullmsg="用户账户不能为空">
                </div>
            </div>



            <div class="row cl">
                <label class="col-sm-3 control-label">拥有权限：</label>

                <div class="formControls col-xs-8 col-sm-9">
                    <foreach name="menu_list" item="me">

                        <dl class="permission-list">
                            <dd>
                                <dl class="cl permission-list2">
                                    <dt>
                                        <label class="1">
                                            <input type="checkbox" class="icheckbox_square-green checked" value="{$me.menu_id}"  name="checkbox[]" <if condition="in_array($me['menu_id'],$mu)">checked="checked"</if>>
                                            {$me.menu_name}</label>
                                    </dt>
                                    <dd>
                                        <foreach name="menu_tow" item="tow">
                                            <if condition="$tow['menu_parent'] eq $me['menu_id'] ">
                                                <label class="2">
                                                    <input type="checkbox" class="icheckbox_square-green checked" value="{$tow.menu_id}" name="checkbox[]" <if condition="in_array($tow['menu_id'],$mu)">checked="checked"</if> />
                                                    {$tow.menu_name}
                                                </label>
                                            </if>
                                        </foreach>
                                    </dd>
                                </dl>
                            </dd>
                        </dl>
                    </foreach>
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <!--<button type="submit" class="btn btn-success radius"  id="admin-role-save" name="admin-role-save">-->
                    <!--<i class="icon-ok"></i> 确定-->
                    <!--</button>-->

                    <button type="button" class="btn btn-success radius"  onclick="getCheckAdIds(this,'{$role_one.role_id}')" id="admin-role-save" name="admin-role-save">
                        <i class="icon-ok"></i> 确定
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<!-- 全局js -->
<include file="Index/common_js"/>
<!-- Peity -->

<!-- 自定义js -->
<script src="__PUBLIC__/admin/js/content.js?v=1.0.0"></script>
<!-- iCheck -->
<script src="__PUBLIC__/admin/js/plugins/iCheck/icheck.min.js"></script>
<!-- Peity -->
<script>
    $(function(){
        $(".permission-list dt input:checkbox").click(function(){
            $(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
        });
        $(".permission-list2 dd input:checkbox").click(function(){
            var n =$(this).parent().parent().find("input:checked").length;
            var n2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
            if($(this).prop("checked")){
                $(this).closest("dl").find("dt input:checkbox").prop("checked",true);
                $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
            } else{
                if(n==0){
                    $(this).closest("dl").find("dt input:checkbox").prop("checked",false);
                }
                if(n2==0){
                    $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
                }
            }
        });
    });


    function getCheckAdIds(obj,id) {
        var roleName= $("#roleName").val();
        var roleResp= $("#roleResp").val();
        var adIds = [];
        $("input:checkbox[type=checkbox]:checked").each(function(i){
            if(0==i){
                adIds = $(this).val();
            }else{
                adIds += (","+$(this).val());
            }
        });
        if(adIds==''){layer.msg('权限不能为空');}else{
            $.post('__MODULE__/System/Role_SaveData',{id:id,role_name:roleName,role_desp:roleResp,checkbox:adIds},function (data) {
                if(data.status==1){
                    layer.msg(data.msg);
                    //setTimeout(function () {location.reload();}, 1000);
                }else if(data.status==0){
                    layer.msg(data.error);
                }else{
                    layer.msg('网络错误');
                }
            })
        }
    }
</script>
</body>
</html>
